<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>注册页面</title>
    <link rel="stylesheet" href="css/main.css" />
    <link rel="stylesheet" href="css/register.css" />
    <link rel="stylesheet" href="iconfont/iconfont.css" />
</head>
<body>
    <!--header开始-->
      <header>
      	<div class="iconfont icon-fanhui mui-action-back"></div>
      	<div style="font-size:0.34rem;color:#fff;opacity: 0;">注册</div>
      	<div style="font-size:0.34rem;color:#fff;">注册</div>
      	<div style="font-size:0.28rem;color:#fff;vertical-align: middle;" class="loginin">登录</div>
      </header>
    <!--header结束-->
    <!--表单的开始-->
    <div class="form">
        <!--手机号-->
        <div  class="username">
    		<div>
    		<img src="img/icon_phone@2x.png" alt=""  style="width:0.36rem;height:0.36rem;margin-right:0.35rem;"/>
    		<input type="text" name="userphone" placeholder="请输入手机号"  id="regPhone"/>
    		</div>
    	</div>
    	<!--密码-->
        <div  class="username">
    		<div>
    		<img src="img/icon_code@2x.png" alt=""  style="width:0.32rem;height:0.40rem;margin-right:0.35rem;"/>
    		<input type="password" name="userpass" placeholder="请输入密码"  id="regPassword"/>
    		</div>
    	</div>
    	<!--验证码-->
        <div  class="username" style="position:relative;">
    		<div>
    		<img src="img/icon_yz@2x.png" alt=""  style="width:0.36rem;height:0.36rem;margin-right:0.35rem;"/>
    		<input type="text" name="phonecode" placeholder="验证码"  id="regVerify"/>
    		<span class="phonecode  idcode-btn base-app-blue2" id="regCodeBtn">获取验证码</span>
    		</div>
    	</div>
    	<!--阅读提示-->
    	<div class="readyread">
    		<div class="readMolgy" id="regNotice">
    			<span class="iconfont icon-duihao active" openshow="openshow" ></span>
    		</div>
    		<span style="font-size:0.24rem;color:#141414;">我已经阅读并同意
    			<i style="font-style: normal;color:#688BB9 ">Molgy用户协议</i></span>
    	</div>
    	<!--创建帐号-->
    	<div type="submit"  id="regBtn">创建帐号</div>
    </div>
    <!--表单的结束-->
</body>
 <script src="js/mui.js"></script>
<script type="text/javascript" src="js/pxtorem.js"></script>
<script type="text/javascript" src="js/apptool.js"></script>
<script type="text/javascript" src="js/httptool.js"></script>
<script type="text/javascript" src="js/loginCenter.js"></script>
<script>
mui.init();
//前台进行验证 

//	点击已经阅读
	function  notice(){
	    mui.toast('请阅读Molgy用户协议');
	    return;
	}
    var openshowflag=true;
	mui('.readyread')[0].addEventListener('tap',function(){ 
		if(openshowflag){
		    mui('span[openshow=openshow]')[0].classList.remove('active');
		    openshowflag=false;
		    mui('#regBtn')[0].addEventListener('tap',notice);
		}else if(!openshowflag){
		    mui('span[openshow=openshow]')[0].classList.add('active');	
		    openshowflag=true;
		    mui('#regBtn')[0].removeEventListener('tap',notice);
		}
	})
var dom = {
	regPhone: mui('#regPhone')[0],
	regVerify: mui('#regVerify')[0],
	regCodeBtn: mui('#regCodeBtn')[0],
	regPassword: mui('#regPassword')[0],
	regBtn: mui('#regBtn')[0],
	regNotice: mui('#regNotice')[0],
}
var codeInfo = {};
var postInfo = {};
var initEvent = function() {
	dom.regPhone.addEventListener('blur',function(e){
		mui.ajax('http://moyu.youledi.cn/moyu/Api/Login/mobileone',{
				data:{
					mobile:dom.regPhone.value,
				},
				dataType:'json',
				type:'post',
				headers:{'Content-Type':'application/json'},	
				success:function(data){
					data=JSON.stringify(data);
					alert(data);
					if(data.code==401){
						mui.toast('该手机号已经注册');
						dom.regCodeBtn.removeEventListener('tap',getCode);
						dom.regCodeBtn.addEventListener('tap',function(){
							mui.toast('该手机号已经注册');
						});
						dom.regPhone.value=="";
						dom.regVerify.value=="";
						dom.regPassword.value=="";
						return;
					}else if(data.code==200){
						 	dom.regBtn.addEventListener('tap', function() {
		if(apptools.checkMobile(dom.regPhone.value)) {
			if(!dom.regPassword.value) {
				mui.toast('密码信息不能为空！');
				return;
			}else if(!dom.regVerify.value) {
				mui.toast('验证码信息不能为空！');
				return;
			}else if(!apptools.checkpass(dom.regPassword.value)){
				return;
            }else {
				mui.ajax('http://moyu.youledi.cn/moyu/Api/Login/register',{
								data:{
									mobile:dom.regPhone.value,
									password:dom.regPassword.value,
									code:dom.regVerify.value,
								},
								dataType:'json',//服务器返回json格式数据
								type:'post',//HTTP请求类型
								headers:{'Content-Type':'application/json'},	              
								success:function(data){
									data=JSON.stringify(data);
									console.log(data);
									console.log(data.code);
									//服务器返回响应，根据响应结果，分析是否登录成功；
									if(data.code==200){
										 mui.toast("注册成功");
										 plus.webview.currentWebview().close();
									}else{
										mui.toast(data.message);
									}
								},
								error:function(xhr,type,errorThrown){
									//异常处理；
									console.log(xhr)
								}
							});
			}
		}
	});
					}else{
						mui.toast(data.message);
					}
				},
				error:function(xhr,type,errorThrown){
						//异常处理；
						console.log(xhr)
				}
		})
	})

	//获取验证码
	function  getCode(){
		var mobileInfo = dom.regPhone.value;
		if(apptools.checkMobile(mobileInfo)) {
			var waiting = apptools.showNativeWaiting();
			codeInfo.mobile = mobileInfo;
			ucenter.getLoginVerify(codeInfo, function(res) {
				var loginWeb = plus.webview.currentWebview();
				if(res.code == 200) {
					waiting.close();
					verifyCount(dom.regCodeBtn, 30);
					mui.toast('短信发送成功...');
				} else {
					waiting.close();
					mui.toast(res.desc);
				}
			})
		}
	}
	dom.regCodeBtn.addEventListener('tap', getCode);
}

mui.plusReady(function(){
	initEvent();
	webtool.backQuit();
	dom.clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
	//点击返回登录
	mui('.loginin')[0].addEventListener('tap',function(){
		webtool.openPreView('login',function(wb){
			wb.show('slide-in-left',300);
		})
	})

})

</script>
</html>